package com.platform.server.controller;

import com.platform.server.dao.ServerDao;
import com.platform.server.entity.DemandOrder;
import com.platform.server.entity.Order;
import com.platform.server.entity.ServerOrder;
import com.platform.server.response.pojo.ReturnData;
import com.platform.server.service.ServerService;
import com.platform.server.util.AuroraPush;
import com.platform.server.util.StringTools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

@Controller
@RequestMapping("/server")
public class ServerController extends BaseController {

    @Autowired
    private ServerService serverService;

    @Autowired
    private ServerDao serverDao;

    /**
     * 选择类型列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectServerList", method = RequestMethod.POST)
    public Object selectServerList() {
        return serverService.selectServerList();
    }

    /**
     * 选择价格列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectPriceList", method = RequestMethod.POST)
    public Object selectPriceList(Integer serverid) {
        return serverService.selectPriceList(serverid);
    }

    /**
     * 获取推荐需求列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectRecommendDemand", method = RequestMethod.POST)
    public Object selectRecommendDemand(String content, String longitude, String latitude) {
        return serverService.selectRecommendDemand(content, longitude, latitude);
    }

    /**
     * 获取推荐服务列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectRecommendServer", method = RequestMethod.POST)
    public Object selectRecommendServer(String content, String longitude, String latitude) {
        return serverService.selectRecommendServer(content, longitude, latitude);
    }

    /**
     * 获取推荐服务列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectRecommendServer2", method = RequestMethod.GET)
    public Object selectRecommendServer2(String content, String longitude, String latitude) {
        return serverService.selectRecommendServer(content, longitude, latitude);
    }

    /**
     * 获取服务列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectServiceList", method = RequestMethod.POST)
    public Object selectServiceList(String type, String option, String longitude, String latitude, Integer pageSize, Integer pageNo, String details, String address) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 1000;
        }
        if (pageSize < 999) {
            pageSize = 1000;
        }
        if (StringTools.isEmpty(longitude) || StringTools.isEmpty(latitude)) {
            return new ReturnData(12, "参数有误");
        }
        return serverService.selectServiceList(type, option, longitude, latitude, pageSize, pageNo, details,address);
    }

    /**
     * 获取需求列表
     */
    @ResponseBody
    @RequestMapping(value = "/selectDemandList", method = RequestMethod.POST)
    public Object selectDemandList(String type, String option, String longitude, String latitude, Integer pageSize, Integer pageNo, String details, String address) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 1000;
        }
        if (pageSize < 999) {
            pageSize = 1000;
        }
        if (StringTools.isEmpty(longitude) || StringTools.isEmpty(latitude)) {
            return new ReturnData(12, "参数有误");
        }
        return serverService.selectDemandList(type, option, longitude, latitude, pageSize, pageNo, details,address);
    }

    /**
     * 发布服务
     */
    @ResponseBody
    @RequestMapping(value = "/publishServer", method = RequestMethod.POST)
    public Object publishServer(ServerOrder server) {
        return serverService.publishServer(server);
    }
    /**
     *修改服务
     */
    @ResponseBody
    @RequestMapping(value = "/updatePublishServer", method = RequestMethod.POST)
    public Object updatePublishServer(ServerOrder server) {
        return serverService.updatePublishServer(server);
    }
    /**
     * 发布需求
     */
    @ResponseBody
    @RequestMapping(value = "/publishDemand", method = RequestMethod.POST)
    public Object publishDemand(DemandOrder server) {
        return serverService.publishDemand(server);
    }
    /**
     * 修改需求
     */
    @ResponseBody
    @RequestMapping(value = "/updatePublishDemand", method = RequestMethod.POST)
    public Object updatePublishDemand(DemandOrder server) {
        return serverService.updatePublishDemand(server);
    }
    /**
     * 关注服务
     */
    @ResponseBody
    @RequestMapping(value = "/concernServer", method = RequestMethod.POST)
    public Object concernServer(String userid, String serverid) {
        return serverService.concernServer(userid, serverid);
    }

    /**
     * 取消关注服务
     */
    @ResponseBody
    @RequestMapping(value = "/cancelConcernServer", method = RequestMethod.POST)
    public Object cancelConcernServer(String userid, String serverid) {
        return serverService.cancelConcernServer(userid, serverid);
    }

    /**
     * 需求资料详情
     */
    @ResponseBody
    @RequestMapping(value = "/selectDemandInfo", method = RequestMethod.POST)
    public Object selectDemandInfo(Integer id, String userid, String type, String longitude, String latitude) {
        return serverService.selectDemandInfo(id, userid, type, longitude, latitude);
    }

    /**
     * 确认预约
     */
    @ResponseBody
    @RequestMapping(value = "/sureMakeServer", method = RequestMethod.POST)
    public Object sureMakeServer(String userid, String serverid, String type, String longitude, String latitude) {
        return serverService.sureMakeServer(userid, serverid, type, longitude, latitude);
    }

    /**
     * 立即预约
     */
    @ResponseBody
    @RequestMapping(value = "/nowMake", method = RequestMethod.POST)
    public Object nowMake(Order order) {
        return serverService.nowMake(order);
    }

    /**
     * 关注需求
     */
    @ResponseBody
    @RequestMapping(value = "/concernDemand", method = RequestMethod.POST)
    public Object concernDemand(String userid, String demandid) {
        return serverService.concernDemand(userid, demandid);
    }

    /**
     * 取消关注需求
     */
    @ResponseBody
    @RequestMapping(value = "/cancelConcernDemand", method = RequestMethod.POST)
    public Object cancelConcernDemand(String userid, String demandid) {
        return serverService.cancelConcernDemand(userid, demandid);
    }

    /**
     * 档期取消订单
     */
    @ResponseBody
    @RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
    public Object cancelOrder(Integer orderid, String userid, String type) throws Exception {
        return serverService.cancelOrder(orderid, userid, type);
    }

    /**
     * 档期确认完成
     */
    @ResponseBody
    @RequestMapping(value = "/confirmOrder", method = RequestMethod.POST)
    public Object confirmOrder(Integer orderid, Integer type) {
        return serverService.confirmOrder(orderid, type);
    }

    /**
     * 档期删除
     */
    @ResponseBody
    @RequestMapping(value = "/deleteServerOrder", method = RequestMethod.POST)
    public Object deleteServerOrder(Integer serverid, String retractor) {
        return serverService.deleteServerOrder(serverid, retractor);
    }

    /**
     * 需求确认完成
     */
    @ResponseBody
    @RequestMapping(value = "/demandSure", method = RequestMethod.POST)
    public Object demandSure(Integer demandid, Integer orderid) {
        return serverService.demandSure(demandid, orderid);
    }

    /**
     * 需求删除
     */
    @ResponseBody
    @RequestMapping(value = "/deleteDemand", method = RequestMethod.POST)
    public Object deleteDemand(Integer demandid, Integer orderid, String retractor) {
        return serverService.deleteDemand(demandid, orderid, retractor);
    }

    /**
     * 需求报名
     */
    @ResponseBody
    @RequestMapping(value = "/applyDemand", method = RequestMethod.POST)
    public Object applyDemand(String demandid, String userid, String longitude, String latitude) {
        return serverService.applyDemand(demandid, userid, longitude, latitude);
    }

    /**
     * 取消需求报名
     */
    @ResponseBody
    @RequestMapping(value = "/cancelApplyDemand", method = RequestMethod.POST)
    public Object cancelApplyDemand(String demandid, String userid) {
        return serverService.cancelApplyDemand(demandid, userid);
    }

    /**
     * 我的档期
     */
    @ResponseBody
    @RequestMapping(value = "/selectUserAuction", method = RequestMethod.POST)
    public Object selectUserAuction(String userid, String type, String byUserid, Integer pageSize, Integer pageNo) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 10;
        }
        return serverService.selectUserAuction(userid, type, byUserid, pageSize, pageNo);
    }

    /**
     * 删除发布服务
     */
    @ResponseBody
    @RequestMapping(value = "/deletePublishServer", method = RequestMethod.POST)
    public Object deletePublishServer(Integer serverid) {
        return serverService.deletePublishServer(serverid);
    }

    /**
     * 档期评价
     */
    @ResponseBody
    @RequestMapping(value = "/auctionAppraise", method = RequestMethod.POST)
    public Object auctionAppraise(String star_level, String give_reward, String content, String upload_image,
                                  String user_id, String comment_id, String service_id, String pay_type, String password) {
        return serverService.auctionAppraise(star_level, give_reward, content, upload_image, user_id, comment_id, service_id, pay_type, request.getRemoteAddr(), password);
    }

    /**
     * 档期详情
     */
    @ResponseBody
    @RequestMapping(value = "/selectAuctionInfo", method = RequestMethod.POST)
    public Object selectAuctionInfo(Integer orderid, String order_type, String userid) {
        return serverService.selectAuctionInfo(orderid, order_type, userid);
    }

    /**
     * 支付违约金30元
     */
    @ResponseBody
    @RequestMapping(value = "/payDamages", method = RequestMethod.POST)
    public Object payDamages(String userid, String gainUserid, String payMethod, String body, String subject, String payMoney,
                             String ip, String password, String oid, String type) throws Exception {
        return serverService.payDamages(userid, gainUserid, payMethod, body, subject, payMoney, request.getRemoteAddr(), password, oid, type);
    }

    /**
     * 我发布的需求
     */
    @ResponseBody
    @RequestMapping(value = "/selectUserIssueDemand", method = RequestMethod.POST)
    public Object selectUserIssueDemand(String userid, String type, Integer pageSize, Integer pageNo) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 10;
        }
        return serverService.selectUserIssueDemand(userid, pageSize, pageNo);
    }

    /**
     * 我报名的需求
     */
    @ResponseBody
    @RequestMapping(value = "/selectUserApplyDemand", method = RequestMethod.POST)
    public Object selectUserApplyDemand(String userid, String type, Integer pageSize, Integer pageNo) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 10;
        }
        return serverService.selectUserApplyDemand(userid, pageSize, pageNo);
    }

    /**
     * 我的需求详情
     */
    @ResponseBody
    @RequestMapping(value = "/selectUserDemandInfo", method = RequestMethod.POST)
    public Object selectUserDemandInfo(Integer demandid, Integer type, String longitude, String latitude, String userid) {
        return serverService.selectUserDemandInfo(demandid, type, longitude, latitude, userid);
    }

    /**
     * 首页
     */
    @ResponseBody
    @RequestMapping(value = "/selectIndexList", method = RequestMethod.POST)
    public Object selectIndexList(String address, String longitude, String latitude, Integer pageSize, Integer pageNo) {
        if (pageSize == null || pageNo == null) {
            pageNo = 1;
            pageSize = 1000;
        }
        if (pageSize < 999) {
            pageSize = 1000;
        }
        return serverService.selectIndexList(address, longitude, latitude, pageSize, pageNo);
    }

    /**
     * 开始服务
     */
    @ResponseBody
    @RequestMapping(value = "/updateOrderStatuIsServer", method = RequestMethod.POST)
    public Object updateOrderStatuIsServer(Integer id) {
        return serverService.updateOrderStatuIsServer(id);
    }

    /**
     * 提醒确认完成
     */
    @ResponseBody
    @RequestMapping(value = "/warnSureFinish", method = RequestMethod.POST)
    public Object warnSureFinish(String userid) {
        if (StringTools.isEmpty(userid)) {
            return new ReturnData(12, "参数有误");
        }
        AuroraPush.pushTargetForDriver(userid, "您的服务已完成，请及时确认！");
        return new ReturnData(200, "成功");
    }

    /**
     * 提醒服务
     */
    @ResponseBody
    @RequestMapping(value = "/warnServer", method = RequestMethod.POST)
    public Object warnServer(String userid) {
        if (StringTools.isEmpty(userid)) {
            return new ReturnData(12, "参数有误");
        }
        AuroraPush.pushTargetForDriver(userid, "您有服务已被预约，请及时前往！");
        return new ReturnData(200, "成功");
    }

    /**
     * 订单提交完成
     */
    @ResponseBody
    @RequestMapping(value = "/orderSubmitFinish", method = RequestMethod.POST)
    public Object orderSubmitFinish(Integer orderid) {
        return serverService.orderSubmitFinish(orderid);
    }

    /**
     * 查看当前用户会员价格
     */
    @ResponseBody
    @RequestMapping(value = "/vip_info", method = RequestMethod.POST)
    public Object userByVipInfo(String userid) {
        return serverService.vipList(userid);
    }

    /**
     * 取消订单
     */
    @ResponseBody
    @RequestMapping(value = "/cancelOrder", method = RequestMethod.GET)
    public Object cancelOrder(Integer orderid, String userid) {
        return serverService.cancelOrder(userid, orderid);
    }

    /**
     * 判断是否迟到
     */
    @ResponseBody
    @RequestMapping(value = "/is_late", method = RequestMethod.GET)
    public Object isLate(Integer orderid) {
        return serverService.isLate(orderid);
    }


}
